extends /templates/core/modal-base-flat

//- DNT
block modal-header-content
  h3 Activate codes

block modal-body-content

  if view.prepaids.size()
    h3.m-t-3#prepaids Existing Prepaids
    table.table.table-condensed
      tr
        th ID
        th Shared by
        th Type
        if view.timeZone == 'Asia/Shanghai'
          th Issued (CT)
          th Start (CT)
          th End (CT)
        else
          th Issued (PT)
          th Start (PT)
          th End (PT)
        th Used
      for prepaid in view.prepaids.models
        - var prepaidControlId=prepaid.id
        tr(id=prepaidControlId)
          td= prepaid.id
          td
            if prepaid.creator
              if prepaid.creator.id !== view.user.id
                a.user-link(data-user-id=prepaid.creator.id)
                  = prepaid.creator.get('name')
              else
                | -
          td= prepaid.get('type')
          td= view.momentTimezone(new Date(parseInt(prepaid.id.substring(0, 8), 16) * 1000)).tz(view.timeZone).format('l')
          td
            if prepaid.get('startDate')
              if view.prepaidTableState && view.prepaidTableState[prepaid.id] === 'editMode'
                - var startDateControlId='startDate-'+prepaid.id
                input(id= startDateControlId type="date" name="startDate" value=view.momentTimezone(prepaid.get('startDate')).tz(view.timeZone).format('YYYY-MM-DD'))
              else
                = view.momentTimezone(prepaid.get('startDate')).tz(view.timeZone).format('l')
          td
            if prepaid.get('endDate')
              if view.prepaidTableState && view.prepaidTableState[prepaid.id] === 'editMode'
                - var endDateControlId='endDate-'+prepaid.id
                input(id= endDateControlId type="date" name="endDate" value=view.momentTimezone(prepaid.get('endDate')).tz(view.timeZone).format('YYYY-MM-DD'))
              else
                = view.momentTimezone(prepaid.get('endDate')).tz(view.timeZone).format('l')
          td
            if view.prepaidTableState && view.prepaidTableState[prepaid.id] === 'editMode'
              - var totalLicensesControlId='totalLicenses-'+prepaid.id
              = (prepaid.get('redeemers') || []).length + ' / '
              input(id=totalLicensesControlId type="number" name="totalLicenses" value=prepaid.get('maxRedeemers'), style="width:50px")
            else
              = (prepaid.get('redeemers') || []).length + ' / ' + prepaid.get('maxRedeemers') || 0
          td
            if view.prepaidTableState && view.prepaidTableState[prepaid.id] === 'editMode'
              button.btn.btn-primary.save-prepaid-info-btn(data-prepaid-id=prepaid.id) Save
              button.btn.btn-primary.cancel-prepaid-info-edit-btn(data-prepaid-id=prepaid.id) Cancel
            else
              button.btn.btn-primary.edit-prepaids-info-btn(data-prepaid-id=prepaid.id) Edit
    hr

  h3.m-t-3#licenses Grant Student Licenses
  #prepaid-form.form
    include ../teachers/common/license-form-group-mixin
    include ../teachers/common/license-type-mixin
    if view.state === 'creating-prepaid'
      .progress.progress-striped.active
        .progress-bar(style="width: 100%")

    else if view.state === 'made-prepaid'
      .alert.alert-success Licenses created!

    else
      if view.timeZone == 'Asia/Shanghai'
        h4.small(style="max-width: 700px") *All licenses granted after Oct 29, 2018 start at 12am CT on the start date and end at 11:59pm CT on the end date listed. All licenses that were granted before that date start and end at 3pm CT on the date listed.
      else
        h4.small(style="max-width: 700px") *All licenses granted after July 9, 2018 start at 12am PT on the start date and end at 11:59pm PT on the end date listed. All licenses that were granted before that date start and end at 5pm PT on the date listed.
      +license-form-group('Number of Activation Codes')(id="seats-input", type='number', name='maxRedeemers', min='1')
      +license-type(view.licenseType, view.licensePresets, view.utils)
      +license-form-group('Duration', ' Days')(type="number" name="duration" value=365)
      +license-form-group('Expiration Date')(type="date" name="endDate" value=view.momentTimezone().tz(view.timeZone).add(1, 'year').format('YYYY-MM-DD'))
      .form-group
        button#add-seats-btn.btn.btn-primary Add Licenses
    hr

block modal-footer
